<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>

  <script>
    // 编写函数，通过传入参数字符串年月日，返回当前日期是当年第几天
    // 2020-12-20
    function day(datestr) {
      var date = new Date(datestr) //传入的日期
      var year = date.getFullYear();
      var nianchu = new Date(year + "-01-01");//2020-01-01
      var diff = date.getTime() - nianchu.getTime();//毫秒差
      console.log(diff)
      var myday = Math.ceil(diff / 1000 / 60 / 60 / 24) + 1;
      return "当前日期是今年的第" + myday + "天"
    }
    console.log(day("2020-02-02"));

  </script>
</body>

</html>